package logic

import (
	"context"
	"errors"
	"short-video-dev/mysql"

	"short-video-dev/videorpc/internal/svc"
	"short-video-dev/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CommentDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCommentDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommentDelLogic {
	return &CommentDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 评论删除
func (l *CommentDelLogic) CommentDel(in *videorpc.CommentDelRequest) (*videorpc.CommentDelResponse, error) {
	// todo: add your logic here and delete this line

	var user mysql.UserInfo
	err := user.FindUserById(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户不存在,请先注册")
	}

	var video mysql.VideoInfo
	err = video.VideoFindByOneId(mysql.DB, in.VideoId)
	if err != nil {
		return nil, errors.New("视频不存在")
	}

	var comment mysql.CommentInfo
	err = comment.FindCommentById(mysql.DB, in)
	if err != nil {
		return nil, errors.New("评论不存在")
	}

	err = comment.DelComment(mysql.DB, in)
	if err != nil {
		return nil, errors.New("删除失败")
	}
	
	return &videorpc.CommentDelResponse{}, nil
}
